package com.zhida.smartcontrol.mvp.permisson;

import android.Manifest;
import android.annotation.SuppressLint;

import com.jay.tools.base.BaseDialogFragment;
import com.tbruyelle.rxpermissions2.RxPermissions;

import io.reactivex.functions.Consumer;

/**
 * author: tanjianpei
 * date: 2018/5/8 008 13:45
 * <p>
 * description: 如果弹出窗口需要权限，需直接继承此类
 */
public abstract class PermissionCheckerDialogFragment extends BaseDialogFragment {
    // 1、申请文件权限
    @SuppressLint("CheckResult")
    protected void requestFilePermission() {
        final RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions.request(
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if (aBoolean) {
                            openFile();
                        } else {

                        }
                    }
                });
    }

    protected void openFile() {
        // 子类实现具体方法
    }

}
